; *** Shogi
; *** Copyright 1998-2002 Zillions Development
; v.2.0

; You need to purchase Zillions of Games to load this rules file
; Visit the Zillions web site at http://www.zillions-of-games.com

(version "2.0")

; Possible additions:
;   Graphics: red for promoted pieces
;   Narrower screen for small screens
(translate
("Mini-Shogi" "5五将棋")("Shogi" "将棋")
("Black" "先手")("White" "后手")
("King" "王")("Gold" "金")
("Rook" "飞")("Promoted-Rook" "龙")
("Bishop" "角")("Promoted-Bishop" "马")
("Silver" "银")("Promoted-Silver" "成银")
("Knight" "桂")("Promoted-Knight" "成桂")
("Lance" "香")("Promoted-Lance" "成香")
("Pawn" "步")("Promoted-Pawn" "と")
)


(define am-white? (not-in-zone? promotion-zone 1i))
(define am-black? (in-zone? promotion-zone 1i))

(define first-empty
   to-prison
   (while not-empty? next-prison)
)
(define convert-prisoner
	change-owner
	(if (flag? bSilver) (change-type Silver))
	(if (flag? bPawn)   (change-type Pawn))
	(if (flag? bBishop) (change-type Bishop))
	(if (flag? bRook)   (change-type Rook))
	(if (flag? bLance)  (change-type Lance))
	(if (flag? bKnight) (change-type Knight))
)
(define prisoner-check
   (if enemy?
   	    (set-flag bSilver (piece? Promoted-Silver))
		(set-flag bPawn   (piece? Tokin))
		(set-flag bBishop (piece? Promoted-Bishop))
		(set-flag bRook   (piece? Promoted-Rook))
		(set-flag bKnight (piece? Promoted-Knight))
		(set-flag bLance  (piece? Promoted-Lance))
        cascade
		mark	
			(first-empty)
			to
			(convert-prisoner)
		back
   )
)

(define shift (
   (verify (in-zone? play-zone))
   $1
   (verify not-friend?)
   (prisoner-check)
   add
))

(define shiftP (
   (verify (in-zone? play-zone))
   (set-flag came-from-zone (in-zone? promotion-zone))
   $1
   (verify not-friend?)
   (prisoner-check)
   (if (in-zone? $3) add)
   (verify (or (flag? came-from-zone) (in-zone? promotion-zone)))
   (if enemy?
       (change-type $2)
	   (if (in-zone? $3) (first-empty) (convert-prisoner))
	   add
	else
	   (add $2)
   )
))

(define shift2P (
   (verify (in-zone? play-zone))
   (set-flag came-from-zone (in-zone? promotion-zone))
   $1
   $2
   (verify not-friend?)
   (prisoner-check)
   (if (in-zone? $4) add)
   (verify (or (flag? came-from-zone) (in-zone? promotion-zone)))
   (if enemy?
       (change-type $3)
	   (if (in-zone? $4) (first-empty) (convert-prisoner))
	   add
	else
	   (add $3)
   )
))

(define slide  (
   (verify (in-zone? play-zone))
   $1 (while empty? add $1)
   (verify not-friend?)
   (prisoner-check)
   add
))

(define slideP (
   (verify (in-zone? play-zone))
   (set-flag came-from-zone (in-zone? promotion-zone))
   $1
   (while empty?
      (if (in-zone? promotion-zone) (set-flag came-from-zone true))
      (if (in-zone? $3) add)
      (if (flag? came-from-zone) (add $2))
      $1
   )
   (verify not-friend?)
   (prisoner-check)
   (if (in-zone? $3) add)
   (verify (or (flag? came-from-zone) (in-zone? promotion-zone)))
   (if enemy?
       (change-type $2)
	   (if (in-zone? $3) (first-empty) (convert-prisoner))
	   add
	else
	   (add $2)
   )
))

(define drop-for-rank
	(while (on-board? e)
		(if empty? add)
		e
	)
	(if empty? add)
)
(define drop ( ; $1 = drop zone
	(verify (not-in-zone? play-zone))
	to-board
	(while (not-in-zone? $1) s)
	(while (on-board? s)
		mark
			(drop-for-rank)
		back
		s
	)
	(drop-for-rank)
))

(define check-dir 
    (if (and (not-flag? bSafe)
	         (on-board? $1)
			 (not-enemy? $1)
	         (not-defended? $1)
		)
      (set-flag bSafe true)
	)
)

(define drop-pawn-for-file
	(set-flag friendly-pawn false)
	mark
		(if (and friend? (piece? Pawn)) (set-flag friendly-pawn true))
		(while (and (not-flag? friendly-pawn) (on-board? s))
			s
			(if (and friend? (piece? Pawn)) (set-flag friendly-pawn true))
		)
	back
	
	(if (not-flag? friendly-pawn)
		mark
			(while (on-board? s)
				s
				(if empty? 
                    ; Check and disallow if it attacks a King with mate
					(if (and (enemy? n) (piece? King n))
					   ; Can undefended Pawn be taken by King
					   ;   or can protected Pawn be taken?
					   (set-flag bSafe (or not-defended? (attacked? no-king)))

					   ; Check if King can make a move in any other direction
					   n
				       (check-dir e)
				       (check-dir w)
				       (check-dir n)
				       (check-dir ne)
				       (check-dir nw)
				       (check-dir se)
				       (check-dir sw)
					   s
					   (if (flag? bSafe) add)
					   		          
				     else
					   add
				    )
			    )
			)
		back
	)
)

(define drop-pawn (
	(verify (not-in-zone? play-zone))
	to-board
	(drop-pawn-for-file)
	(while (on-board? e)
		e
		(drop-pawn-for-file)
	)
))

; *********************************************************************
;  MINI-SHOGI
; *********************************************************************
(game
    (title "5五将棋（Mini-Shogi）")
	(description "将死敌方王将胜利。\\
将棋为三大象棋系之一。将棋有独特的规则：\\
在将棋中，吃掉对方的子之后，把它放到自己一方的驹台(一般位于你的右边)，称为“持子”。你可以花一步棋，不走盘上的棋子，而是将持子作为你方棋子放回盘上，称为“打入”。\
打入有如下限制：\不可把棋子打入无法再移动的区域，如步兵不可打入对方底线。\同一条直线上不可有两个(未升级的)步兵，称为“二步”。\不可通过打入步兵直接将死对方，称为“打步诘”。\
另外，将棋棋子的升级规则如下：当你的棋子进入对手三行，即“敌阵”内，或在敌阵内移动，或走出敌阵时，即可升级。升级后的棋子若被吃，只能以原形态打入。右键点击棋子查看它的走法以及升级走法。")
	(strategy "It is good to occupy the center square.  Develop quickly and use
	     your initiative to attack the enemy King.  Because of the small board,
	     Bishops and Rooks do not dominate as much as they do in normal Shogi.
           Material is very important, especially the number of pieces you have to drop.")
	(history "Rediscovered by Shigeo Kusumoto around 1970, this variant became
		popular in Japan.  An association was formed for it in Osaka.   Mini-Shogi
            is one of a number of variants of the standard 9x9 game.  Most of these are
            large-board games: Chu or Middle Shogi, played on a 12x12 board, is the most
            popular of these, and most of the larger games are rarely played.   A few
            small-board games, including Tori Shogi (7x7) and Poppy Shogi (4x5) are also
            played.")
    (option "prevent flipping" true)
    (opening-sound "Audio\\Japan1.wav")
    (win-sound "Audio\\Japan2.wav")
    (loss-sound "Audio\\Japan2.wav")
    (release-sound "Audio\\BongPercussive.wav")
    (move-sound "Audio\\Bong5th.wav")
    (capture-sound "Audio\\WoodBells.wav")
    (players Black White)
    (turn-order Black White)
	(board
        (image "images\Shogi\SHaag\Shogi5x5Brd.bmp" "images\Shogi\IntlSHaag\Shogi5x5Brd.bmp" "images\Shogi\Shogi5x5Brd.bmp")
        (grid
            (start-rectangle 138 15 178 60)
            (dimensions ;5x5
                ("5/4/3/2/1" (41 0))
                ("i/ii/iii/iv/v" (0 46))
            )
            (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
			     (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
            )
		)
		(positions
			(pw2 15  15 55  60) (pb2 385  15 425  60)
			(pw4 15  61 55 106) (pb4 385  61 425 106)
			(pw6 15 107 55 152) (pb6 385 107 425 152)
			(pw8 15 153 55 198) (pb8 385 153 425 198)
			(pw0 15 199 55 244) (pb0 385 199 425 244)

			(pw1 56  15 96  60) (pb1 426  15 466  60)
			(pw3 56  61 96 106) (pb3 426  61 466 106)
			(pw5 56 107 96 152) (pb5 426 107 466 152)
			(pw7 56 153 96 198) (pb7 426 153 466 198)
			(pw9 57 199 97 244) (pb9 426 199 466 244)
		)
		(links to-prison
			(5i pb0) (4i pb0) (3i pb0) (2i pb0) (1i pb0)
			(5ii pb0) (4ii pb0) (3ii pb0) (2ii pb0) (1ii pb0)
			(5iii pb0) (4iii pb0) (3iii pb0) (2iii pb0) (1iii pb0)
			(5iv pb0) (4iv pb0) (3iv pb0) (2iv pb0) (1iv pb0)
			(5v pb0) (4v pb0) (3v pb0) (2v pb0) (1v pb0)
 		)

		(links to-white-prison ; associated with to-prison through symmetry
			(5i pw1) (4i pw1) (3i pw1) (2i pw1) (1i pw1)
			(5ii pw1) (4ii pw1) (3ii pw1) (2ii pw1) (1ii pw1)
			(5iii pw1) (4iii pw1) (3iii pw1) (2iii pw1) (1iii pw1)
			(5iv pw1) (4iv pw1) (3iv pw1) (2iv pw1) (1iv pw1)
			(5v pw1) (4v pw1) (3v pw1) (2v pw1) (1v pw1)
		)

		(links next-prison
			(pb0 pb9) (pb9 pb8) (pb8 pb7) (pb7 pb6) (pb6 pb5) (pb5 pb4) (pb4 pb3) (pb3 pb2) (pb2 pb1)
			(pw1 pw2) (pw2 pw3) (pw3 pw4) (pw4 pw5) (pw5 pw6) (pw6 pw7) (pw7 pw8) (pw8 pw9) (pw9 pw0)
		)
		(links to-board
			(pb1 5i) (pb2 5i) (pb3 5i) (pb4 5i) (pb5 5i) (pb6 5i) (pb7 5i) (pb8 5i) (pb9 5i) (pb0 5i)
			(pw1 5v) (pw2 5v) (pw3 5v) (pw4 5v) (pw5 5v) (pw6 5v) (pw7 5v) (pw8 5v) (pw9 5v) (pw0 5v)
		)

		(symmetry White (to-prison to-white-prison))
        (symmetry White (n s)(s n) (nw sw)(sw nw) (ne se)(se ne))
        (zone
           (name play-zone)
           (players White Black)
           (positions
		      5i 4i 3i 2i 1i
              5ii 4ii 3ii 2ii 1ii
              5iii 4iii 3iii 2iii 1iii
              5iv 4iv 3iv 2iv 1iv
              5v 4v 3v 2v 1v
 		   )
        )
        (zone
           (name promotion-zone)
           (players Black)
           (positions 5i 4i 3i 2i 1i)
        )
        (zone
           (name promotion-zone)
           (players White)
           (positions 5v 4v 3v 2v 1v)
        )
        (zone
           (name prison-zone)
           (players Black)
           (positions pb1 pb2 pb3 pb4 pb5 pb6 pb7 pb8 pb9 pb0)
        )
        (zone
           (name prison-zone)
           (players White)
           (positions pw1 pw2 pw3 pw4 pw5 pw6 pw7 pw8 pw9 pw0)
        )
		(zone
		   (name drop-pawn-zone)
           (players Black)
           (positions
              5ii 4ii 3ii 2ii 1ii
              5iii 4iii 3iii 2iii 1iii
              5iv 4iv 3iv 2iv 1iv
              5v 4v 3v 2v 1v
	       )
        )
		(zone
		   (name drop-pawn-zone)
           (players White)
           (positions
		      5i 4i 3i 2i 1i
              5ii 4ii 3ii 2ii 1ii
              5iii 4iii 3iii 2iii 1iii
              5iv 4iv 3iv 2iv 1iv
 	       )
        )

		;following are fake, not used in mini-shogi
		(zone
		   (name drop-knight-zone)
           (players Black)
           (positions 5i)
        )
		(zone
		   (name drop-knight-zone)
           (players White)
           (positions 5i)
        )
	)
    (board-setup
        (White (Pawn 1ii)
               (King 1i)
               (Gold 2i)
               (Silver 3i)
               (Bishop 4i)
               (Rook 5i)
        )
        (Black (Pawn 5iv)
               (King 5v)
               (Gold 4v)
               (Silver 3v)
               (Bishop 2v)
               (Rook 1v)
        )
    )

    (piece
		(name Pawn)
		(image White "images\Shogi\SHaag\PawnFlip.bmp" "images\Shogi\IntlSHaag\PawnFlip.bmp" "images\Shogi\PawnFlip.bmp" 
                       Black "images\Shogi\SHaag\Pawn.bmp"     "images\Shogi\IntlSHaag\Pawn.bmp"     "images\Shogi\Pawn.bmp" )
   	    (help "步兵：只能向前走一步。成金将（と金）。")
		(description "步兵\步兵只能向前移动一格。\\步兵成と金，走法同金将。")
        (moves
           (move-type with-king)
           (shiftP n Tokin drop-pawn-zone)
           (drop-pawn)
        )
    )
    (piece
		(name Tokin)
		(image White "images\Shogi\SHaag\PawnPFlip.bmp" "images\Shogi\IntlSHaag\PawnPFlip.bmp" "images\Shogi\PawnPFlip.bmp" 
                       Black "images\Shogi\SHaag\PawnP.bmp"     "images\Shogi\IntlSHaag\PawnP.bmp"     "images\Shogi\PawnP.bmp")
 	    (help "と金：横直一格，或斜前一格。")
		(description "と金\由步兵升级而来。\走法与金将相同，即可以斜前，或前后左右移动一格。")
        (moves ; like a Gold General
		    (move-type no-king)
            (shift nw)
            (shift n)
            (shift ne)
            (shift e)
            (shift w)
            (shift s)
            (drop-pawn)
        )
    )
 
    (piece
		(name Silver)
		(image White "images\Shogi\SHaag\SilverFlip.bmp" "images\Shogi\IntlSHaag\SilverFlip.bmp" "images\Shogi\SilverFlip.bmp" 
                       Black "images\Shogi\SHaag\Silver.bmp"     "images\Shogi\IntlSHaag\Silver.bmp"     "images\Shogi\Silver.bmp")
   	    (help "银将：斜行一格或正前方一格")
        (description "银将(银)\银将不行左右下。即：银将不可左右移动，不可后退。但可以其他方向移动一格，即可以斜走一格，或前进一格。\升级为成银，走法与金将相同。")
        (moves
            (move-type no-king)
            (shiftP nw Promoted-Silver play-zone)
            (shiftP n  Promoted-Silver play-zone)
            (shiftP ne Promoted-Silver play-zone)
            (shiftP sw Promoted-Silver play-zone)
            (shiftP se Promoted-Silver play-zone)
            (drop play-zone)
        )
    )
    (piece
		(name Promoted-Silver)
		(image White "images\Shogi\SHaag\SilverPFlip.bmp" "images\Shogi\IntlSHaag\SilverPFlip.bmp" "images\Shogi\SilverPFlip.bmp"
                       Black "images\Shogi\SHaag\SilverP.bmp"     "images\Shogi\IntlSHaag\SilverP.bmp"     "images\Shogi\SilverP.bmp")
 	    (help "成银：横直一格，或斜前一格。")
        (description "成银\由银将升级而来，走法同金将，即横直一格，斜前一格。")
        (moves
            (move-type no-king)
            (shift nw)
            (shift n)
            (shift ne)
            (shift e)
            (shift w)
            (shift s)
            (drop play-zone)
        )
    )

    (piece
		(name Gold)
		(image White "images\Shogi\SHaag\GoldFlip.bmp" "images\Shogi\IntlSHaag\GoldFlip.bmp" "images\Shogi\GoldFlip.bmp"
                       Black "images\Shogi\SHaag\Gold.bmp"     "images\Shogi\IntlSHaag\Gold.bmp"     "images\Shogi\Gold.bmp")
 	    (help "金将：横直一格，或斜前一格。")
        (description "金将(金)\金将不行下二目，即金将无法斜着后退，只能斜前移动一格，或横竖移动一格。\金将不升级。")
		(moves
		    (move-type no-king)
            (shift nw)
            (shift n)
            (shift ne)
            (shift e)
            (shift w)
            (shift s)
            (drop play-zone)
        )
    )

    (piece
		(name Bishop)
		(image White "images\Shogi\SHaag\BishopFlip.bmp" "images\Shogi\IntlSHaag\BishopFlip.bmp" "images\Shogi\BishopFlip.bmp"
		       Black "images\Shogi\SHaag\Bishop.bmp"     "images\Shogi\IntlSHaag\Bishop.bmp"     "images\Shogi\Bishop.bmp")
	    (help"角行：斜向移动，不限格数")
        (description "角行(角)\角行走斜线，格数不限\升级成龙马，增加可以横竖一格的能力。")
        (moves
		   (move-type no-king)
           (slideP ne Promoted-Bishop play-zone)
           (slideP nw Promoted-Bishop play-zone)
           (slideP se Promoted-Bishop play-zone)
           (slideP sw Promoted-Bishop play-zone)
           (drop play-zone)
        )
    )
    (piece
		(name Promoted-Bishop)
 		(image White "images\Shogi\SHaag\BishopPFlip.bmp" "images\Shogi\IntlSHaag\BishopPFlip.bmp" "images\Shogi\BishopPFlip.bmp"
		       Black "images\Shogi\SHaag\BishopP.bmp"     "images\Shogi\IntlSHaag\BishopP.bmp"     "images\Shogi\BishopP.bmp")
        (help "龙马：角行+王")
        (description "龙马(马)\由角行升级。龙马可以斜走，格数不限。除此之外，还可以横向或纵向走一格。")
        (moves
		   (move-type no-king)
           (slide ne)
           (slide nw)
           (slide se)
           (slide sw)
           (shift n)
           (shift s)
           (shift e)
           (shift w)
           (drop play-zone)
        )
    )

    (piece
       (name Rook)
       (image White "images\Shogi\SHaag\RookFlip.bmp" "images\Shogi\IntlSHaag\RookFlip.bmp" "images\Shogi\RookFlip.bmp"
              Black "images\Shogi\SHaag\Rook.bmp"     "images\Shogi\IntlSHaag\Rook.bmp"     "images\Shogi\Rook.bmp")
       (help "飞车：横直均可，格数不限。")
       (description "飞车(飞)\飞车可横向或纵向移动，格数不限。\飞车成龙王，增加可斜向移动一格的能力。")
       (moves
	       (move-type no-king)
           (slideP n Promoted-Rook play-zone)
           (slideP s Promoted-Rook play-zone)
           (slideP e Promoted-Rook play-zone)
           (slideP w Promoted-Rook play-zone)
           (drop play-zone)
        )
    )
    (piece
		(name Promoted-Rook)
 		(image White "images\Shogi\SHaag\RookPFlip.bmp" "images\Shogi\IntlSHaag\RookPFlip.bmp" "images\Shogi\RookPFlip.bmp"
 		       Black "images\Shogi\SHaag\RookP.bmp"     "images\Shogi\IntlSHaag\RookP.bmp"     "images\Shogi\RookP.bmp")
        (help "龙王：飞车+王")
        (description "龙王(龙)\龙王由飞车升级而来。可以横向或纵向不限格数行走，或斜走一格。")
        (moves
		   (move-type no-king)
           (slide n)
           (slide s)
           (slide e)
           (slide w)
           (shift nw)
           (shift ne)
           (shift sw)
           (shift se)
           (drop play-zone)
        )
    )

	(piece
		(name Lance)
		(image White "images\Shogi\SHaag\LanceFlip.bmp" "images\Shogi\IntlSHaag\LanceFlip.bmp" "images\Shogi\LanceFlip.bmp"
		       Black "images\Shogi\SHaag\Lance.bmp"     "images\Shogi\IntlSHaag\Lance.bmp"     "images\Shogi\Lance.bmp")
 	    (help "香车：向前移动，格数不限")
 		(description "香车(香)\香车只能向前移动，格数不限。\升级走法同金将。")
        (moves
		   (move-type no-king)
           (slideP n Promoted-Lance drop-pawn-zone)
 		   (drop drop-pawn-zone)
        )
    )
    (piece
		(name Promoted-Lance)
		(image White "images\Shogi\SHaag\LancePFlip.bmp" "images\Shogi\IntlSHaag\LancePFlip.bmp" "images\Shogi\LancePFlip.bmp"
		       Black "images\Shogi\SHaag\LanceP.bmp"     "images\Shogi\IntlSHaag\LanceP.bmp"     "images\Shogi\LanceP.bmp")
 	    (help "成香：横直一格，或斜前一格。")
		(description "成香(杏)\由香车升级而来。走法与金将相同，即横直一格，或斜前一格。")
        (moves ; like a Gold General
		    (move-type no-king)
            (shift nw)
            (shift n)
            (shift ne)
            (shift e)
            (shift w)
            (shift s)
            (drop play-zone)
        )
    )

    (piece
		(name Knight)
		(image White "images\Shogi\SHaag\KnightFlip.bmp" "images\Shogi\IntlSHaag\KnightFlip.bmp" "images\Shogi\KnightFlip.bmp"
		       Black "images\Shogi\SHaag\Knight.bmp"     "images\Shogi\IntlSHaag\Knight.bmp"     "images\Shogi\Knight.bmp")
  	    (help "桂马：向前一格然后斜前一格，可以越子")
		(description "桂马(桂)\桂马是只能向前跳“日”字的马。即先往前一步，然后在斜前一步。可以越子。\升级走法同金将。")
        (moves
		    (move-type no-king)
            (shift2P n nw Promoted-Knight drop-knight-zone)
            (shift2P n ne Promoted-Knight drop-knight-zone)
            (drop drop-knight-zone)
        )
    )
    (piece
		(name Promoted-Knight)
 		(image White "images\Shogi\SHaag\KnightPFlip.bmp" "images\Shogi\IntlSHaag\KnightPFlip.bmp" "images\Shogi\KnightPFlip.bmp"
		       Black "images\Shogi\SHaag\KnightP.bmp"     "images\Shogi\IntlSHaag\KnightP.bmp"     "images\Shogi\KnightP.bmp")
 	    (help "成桂：横直一格，或斜前一格。")
		(description "成桂(圭)\由桂马升级而来。走法同金将，即横直一格，或斜前一格。")
        (moves ; like a Gold General
		    (move-type no-king)
            (shift nw)
            (shift n)
            (shift ne)
            (shift e)
            (shift w)
            (shift s)
            (drop drop-knight-zone)
        )
    )

    (piece
		(name King)
		(image White "images\Shogi\SHaag\KingFlip.bmp" "images\Shogi\IntlSHaag\KingFlip.bmp" "images\Shogi\KingFlip.bmp"
		       Black "images\Shogi\SHaag\King.bmp"     "images\Shogi\IntlSHaag\King.bmp"     "images\Shogi\King.bmp")
		(help "王将：八方一格，不可送吃")
        (description "王将(王)\八方一格，被将死输棋。\不可送吃。")
        (moves
		    (move-type with-king)
            (shift nw)
            (shift n)
            (shift ne)
            (shift e)
            (shift w)
            (shift sw)
            (shift se)
            (shift s)
        )
    )

    (loss-condition (White Black) (checkmated King) )
)

; *********************************************************************
;  SHOGI
; *********************************************************************
(define ranki        9i 8i 7i 6i 5i 4i 3i 2i 1i)
(define rankii       9ii 8ii 7ii 6ii 5ii 4ii 3ii 2ii 1ii)
(define rankiii      9iii 8iii 7iii 6iii 5iii 4iii 3iii 2iii 1iii)
(define rankiv-vi    9iv 8iv 7iv 6iv 5iv 4iv 3iv 2iv 1iv
                     9v 8v 7v 6v 5v 4v 3v 2v 1v
                     9vi 8vi 7vi 6vi 5vi 4vi 3vi 2vi 1vi)
(define rankvii      9vii 8vii 7vii 6vii 5vii 4vii 3vii 2vii 1vii)
(define rankviii     9viii 8viii 7viii 6viii 5viii 4viii 3viii 2viii 1viii)
(define rankix       9ix 8ix 7ix 6ix 5ix 4ix 3ix 2ix 1ix)
(define wprison
        pw3i    pw2i    pw1i  
	  pw3ii   pw2ii   pw1ii
	  pw3iii  pw2iii  pw1iii
	  pw3iv   pw2iv   pw1iv
	  pw3v    pw2v    pw1v
	  pw3vi   pw2vi   pw1vi
	  pw3vii  pw2vii  pw1vii
	  pw3viii pw2viii pw1viii
	  pw3ix   pw2ix   pw1ix
)
(define bprison
      pb1i    pb2i    pb3i
      pb1ii   pb2ii   pb3ii
      pb1iii  pb2iii  pb3iii
      pb1iv   pb2iv   pb3iv
	pb1v    pb2v    pb3v
	pb1vi   pb2vi   pb3vi
	pb1vii  pb2vii  pb3vii
	pb1viii pb2viii pb3viii
	pb1ix   pb2ix   pb3ix
)
(variant
    (title "将棋")
    (default)
	(description "将死敌方王将胜利。\\
将棋为三大象棋系之一。将棋有独特的规则：\\
在将棋中，吃掉对方的子之后，把它放到自己一方的驹台(一般位于你的右边)，称为“持子”。你可以花一步棋，不走盘上的棋子，而是将持子作为你方棋子放回盘上，称为“打入”。\
打入有如下限制：\不可把棋子打入无法再移动的区域，如步兵不可打入对方底线。\同一条直线上不可有两个(未升级的)步兵，称为“二步”。\不可通过打入步兵直接将死对方，称为“打步诘”。\
另外，将棋棋子的升级规则如下：当你的棋子进入对手三行，即“敌阵”内，或在敌阵内移动，或走出敌阵时，即可升级。升级后的棋子若被吃，只能以原形态打入。右键点击棋子查看它的走法以及升级走法。")
	(strategy "Keep the squares in your camp protected to keep your opponent
		from dropping his pieces there.  In particular the squares around
		your King must be well guarded.   Middle game play is heavily influenced
            by play (and threats to play) from the reserves.    Watch for squares
            (on both sides) vulnerable to drops.    A good way to defend against
            a drop on a particular square is to move or drop a piece to that
            square yourself.  In Shogi, unlike Western Chess, material isn't so
            important once the Kings are attacked.  What is important is initiative
            or `sente`; many games end in `races` to see which player can mate the
            opposing king more quickly.\\
            The relative values of the initial pieces may be: Rook - Bishop -
            Gold/Silver - Lance/Knight - Pawn.   Golds are slightly better than
            Silvers, especially for defense.  Lances and Knights are only useful
            for offense; since they are weak, they want to push forward and promote
            when possible.   Pawns are not worth very much until they approach the
            promotion zone, but a pawn in hand (i.e. part of the reserve of captured
            pieces) can be very useful.\\
            The game is widely covered in Japanese books, magazines, and newspapers.
            Some detailed books and magazines in English on shogi strategy
            can be found at http://www.zillions-of-games.com/shogi.html.")
	(history "Growing slowly in popularity outside of Japan, Shogi, the Japanese
            form of Chess, is perhaps the most popular board game in Japan, with
            perhaps a million active players.   Some early form of chess was imported
            into Japan (perhaps from Korea or Thailand), probably between the 10th
            and 12th centuries.   In the 16th century a rule was added (perhaps
            inspired by the changeable loyalties of mercenaries), allowing captured
            pieces to be re-used by the capturer, which sets shogi apart from all
            other chesslike games.   Other larger forms of the game have been recorded
            (up to the inconceivable 25x25 Tai Shogi), but these have largely died
            out, except for the 12x12 Chu (Middle) Shogi.    The Nihon Shogi Remmei
            (Japan Shogi Federation), formed in 1927, regulates play, conducts
            tournaments, and maintains player rankings.")  
    (board
        (image "images\Shogi\SHaag\ShogiBrd.bmp" "images\Shogi\IntlSHaag\ShogiBrd.bmp" "images\Shogi\ShogiBrd.bmp")
        (grid
            (start-rectangle 15 15 55 60) ; 22 25 62 70)
            (dimensions ;17x9

				; za = zb = "no mans land" area between board and prisons
				; pb1-3 = black's prison table
				; pw1-3 = white's prison table

                ("pw3/pw2/pw1/za/9/8/7/6/5/4/3/2/1/zb/pb1/pb2/pb3" (41 0))
                ("i/ii/iii/iv/v/vi/vii/viii/ix" (0 46))
            )
            (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
			     (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
            )
		)

		; delete "no mans land"
		(kill-positions
			zai zaii zaiii zaiv zav zavi zavii zaviii zaix
			zbi zbii zbiii zbiv zbv zbvi zbvii zbviii zbix
		)
		(unlink (wprison) (bprison))
 
		; setup prisoners chains (is there a better way to specify a general many to one link?)
		(links to-prison
			(9i pb1ix) (8i pb1ix) (7i pb1ix) (6i pb1ix) (5i pb1ix) (4i pb1ix) (3i pb1ix) (2i pb1ix) (1i pb1ix)
            (9ii pb1ix) (8ii pb1ix) (7ii pb1ix) (6ii pb1ix) (5ii pb1ix) (4ii pb1ix) (3ii pb1ix) (2ii pb1ix) (1ii pb1ix)
            (9iii pb1ix) (8iii pb1ix) (7iii pb1ix) (6iii pb1ix) (5iii pb1ix) (4iii pb1ix) (3iii pb1ix) (2iii pb1ix) (1iii pb1ix)
            (9iv pb1ix) (8iv pb1ix) (7iv pb1ix) (6iv pb1ix) (5iv pb1ix) (4iv pb1ix) (3iv pb1ix) (2iv pb1ix) (1iv pb1ix)
            (9v pb1ix) (8v pb1ix) (7v pb1ix) (6v pb1ix) (5v pb1ix) (4v pb1ix) (3v pb1ix) (2v pb1ix) (1v pb1ix)
            (9vi pb1ix) (8vi pb1ix) (7vi pb1ix) (6vi pb1ix) (5vi pb1ix) (4vi pb1ix) (3vi pb1ix) (2vi pb1ix) (1vi pb1ix)
            (9vii pb1ix) (8vii pb1ix) (7vii pb1ix) (6vii pb1ix) (5vii pb1ix) (4vii pb1ix) (3vii pb1ix) (2vii pb1ix) (1vii pb1ix)
            (9viii pb1ix) (8viii pb1ix) (7viii pb1ix) (6viii pb1ix) (5viii pb1ix) (4viii pb1ix) (3viii pb1ix) (2viii pb1ix) (1viii pb1ix)
            (9ix pb1ix) (8ix pb1ix) (7ix pb1ix) (6ix pb1ix) (5ix pb1ix) (4ix pb1ix) (3ix pb1ix) (2ix pb1ix) (1ix pb1ix)
		)

		(links to-white-prison ; associated with to-prison through symmetry
			(9i pw1i) (8i pw1i) (7i pw1i) (6i pw1i) (5i pw1i) (4i pw1i) (3i pw1i) (2i pw1i) (1i pw1i)
            (9ii pw1i) (8ii pw1i) (7ii pw1i) (6ii pw1i) (5ii pw1i) (4ii pw1i) (3ii pw1i) (2ii pw1i) (1ii pw1i)
            (9iii pw1i) (8iii pw1i) (7iii pw1i) (6iii pw1i) (5iii pw1i) (4iii pw1i) (3iii pw1i) (2iii pw1i) (1iii pw1i)
            (9iv pw1i) (8iv pw1i) (7iv pw1i) (6iv pw1i) (5iv pw1i) (4iv pw1i) (3iv pw1i) (2iv pw1i) (1iv pw1i)
            (9v pw1i) (8v pw1i) (7v pw1i) (6v pw1i) (5v pw1i) (4v pw1i) (3v pw1i) (2v pw1i) (1v pw1i)
            (9vi pw1i) (8vi pw1i) (7vi pw1i) (6vi pw1i) (5vi pw1i) (4vi pw1i) (3vi pw1i) (2vi pw1i) (1vi pw1i)
            (9vii pw1i) (8vii pw1i) (7vii pw1i) (6vii pw1i) (5vii pw1i) (4vii pw1i) (3vii pw1i) (2vii pw1i) (1vii pw1i)
            (9viii pw1i) (8viii pw1i) (7viii pw1i) (6viii pw1i) (5viii pw1i) (4viii pw1i) (3viii pw1i) (2viii pw1i) (1viii pw1i)
            (9ix pw1i) (8ix pw1i) (7ix pw1i) (6ix pw1i) (5ix pw1i) (4ix pw1i) (3ix pw1i) (2ix pw1i) (1ix pw1i)
		)

		(links next-prison
			(pb1ix pb2ix) (pb2ix pb3ix) (pb3ix pb1viii)
			(pb1viii pb2viii) (pb2viii pb3viii) (pb3viii pb1vii)
			(pb1vii pb2vii) (pb2vii pb3vii) (pb3vii pb1vi)
			(pb1vi pb2vi) (pb2vi pb3vi) (pb3vi pb1v)
			(pb1v pb2v) (pb2v pb3v) (pb3v pb1iv) 
			(pb1iv pb2iv) (pb2iv pb3iv) (pb3iv pb1iii)
			(pb1iii pb2iii) (pb2iii pb3iii) (pb3iii pb1ii)
			(pb1ii pb2ii) (pb2ii pb3ii) (pb3ii pb1i)
			(pb1i pb2i) (pb2i pb3i)

			(pw1i pw2i) (pw2i pw3i) (pw3i pw1ii)
			(pw1ii pw2ii) (pw2ii pw3ii) (pw3ii pw1iii)
			(pw1iii pw2iii) (pw2iii pw3iii) (pw3iii pw1iv)
			(pw1iv pw2iv) (pw2iv pw3iv) (pw3iv pw1v)
			(pw1v pw2v) (pw2v pw3v) (pw3v pw1vi)
			(pw1vi pw2vi) (pw2vi pw3vi) (pw3vi pw1vii)
			(pw1vii pw2vii) (pw2vii pw3vii) (pw3vii pw1viii)
			(pw1viii pw2viii) (pw2viii pw3viii) (pw3viii pw1ix)
	            (pw1ix pw2ix) (pw2ix pw3ix) 
		)
		(links to-board
               (pw3i 9ix)    (pw2i 9ix)    (pw1i 9ix)  
		   (pw3ii 9ix)   (pw2ii 9ix)   (pw1ii 9ix)
		   (pw3iii 9ix)  (pw2iii 9ix)  (pw1iii 9ix)
		   (pw3iv 9ix)   (pw2iv 9ix)   (pw1iv 9ix) 
		   (pw3v 9ix)    (pw2v 9ix)    (pw1v 9ix)
		   (pw3vi 9ix)   (pw2vi 9ix)   (pw1vi 9ix)
		   (pw3vii 9ix)  (pw2vii 9ix)  (pw1vii 9ix)
		   (pw3viii 9ix) (pw2viii 9ix) (pw1viii 9ix)
		   (pw3ix 9ix)   (pw2ix 9ix)   (pw1ix 9ix)

               (pb1i 9i)     (pb2i 9i)     (pb3i 9i)
		   (pb1ii 9i)    (pb2ii 9i)    (pb3ii 9i)
		   (pb1iii 9i)   (pb2iii 9i)   (pb3iii 9i)
		   (pb1iv 9i)    (pb2iv 9i)    (pb3iv 9i)
		   (pb1v 9i)     (pb2v 9i)     (pb3v 9i)
		   (pb1vi 9i)    (pb2vi 9i)    (pb3vi 9i)
		   (pb1vii 9i)   (pb2vii 9i)   (pb3vii 9i)
		   (pb1viii 9i)  (pb2viii 9i)  (pb3viii 9i)
		   (pb1ix 9i)    (pb2ix 9i)    (pb3ix 9i)
		)

		(symmetry White (to-prison to-white-prison))
            (symmetry White (n s)(s n) (nw sw)(sw nw) (ne se)(se ne))

        (zone
           (name play-zone)
           (players White Black)
           (positions (ranki) (rankii) (rankiii) (rankiv-vi) (rankvii) (rankviii) (rankix))
        )
        (zone
           (name promotion-zone)
           (players Black)
           (positions (ranki) (rankii) (rankiii))
        )
        (zone
           (name promotion-zone)
           (players White)
           (positions (rankvii) (rankviii) (rankix))
        )
        (zone
           (name prison-zone)
           (players Black)
           (positions (bprison))
        )
        (zone
           (name prison-zone)
           (players White)
           (positions (wprison))
        )
		(zone
		   (name drop-pawn-zone) ; lance also
           (players Black)
           (positions (rankii) (rankiii) (rankiv-vi) (rankvii) (rankviii) (rankix))
        )
		(zone
		   (name drop-pawn-zone) ; lance also
           (players White)
           (positions (ranki) (rankii) (rankiii) (rankiv-vi) (rankvii) (rankviii))
        )
		(zone
		   (name drop-knight-zone)
           (players Black)
           (positions (rankiii) (rankiv-vi) (rankvii) (rankviii) (rankix))
        )
		(zone
		   (name drop-knight-zone)
           (players White)
           (positions (ranki) (rankii) (rankiii) (rankiv-vi) (rankvii))
        )
    )

    (board-setup
        (White (Pawn (rankiii))
               (Lance 9i 1i)
               (Knight 8i 2i)
               (Silver 7i 3i)
               (Gold 6i 4i)
               (Bishop 2ii)
               (Rook 8ii)
               (King 5i)
        )
        (Black (Pawn (rankvii))
               (Lance 9ix 1ix)
               (Knight 8ix 2ix)
               (Silver 7ix 3ix)
               (Gold 6ix 4ix)
               (Bishop 8viii)
               (Rook 2viii)
               (King 5ix)
        )
    )

    
)
